package com.ruoyi.web.controller.job;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.YnStatusEnum;
import com.ruoyi.system.domain.JobPlanBillDeclareOperate;
import com.ruoyi.system.domain.vo.DeleteVo;
import com.ruoyi.system.service.JobPlanBillDeclareOperateService;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 作业票申报操作表(JobPlanBillDeclareOperate)表控制层
 *
 * @author makejava
 * @since 2023-06-06 14:07:55
 */
@RestController
@RequestMapping("jobPlanBillDeclareOperate")
public class JobPlanBillDeclareOperateController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private JobPlanBillDeclareOperateService jobPlanBillDeclareOperateService;

    /**
     * 分页查询
     *
     * @param jobPlanBillDeclareOperate 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public TableDataInfo queryByPage(JobPlanBillDeclareOperate jobPlanBillDeclareOperate) {
        startPage();
        List<JobPlanBillDeclareOperate> list = jobPlanBillDeclareOperateService.queryAll(jobPlanBillDeclareOperate);
        return getDataTable(list);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<JobPlanBillDeclareOperate> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.jobPlanBillDeclareOperateService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param jobPlanBillDeclareOperate 实体
     * @return 新增结果
     */
    @PostMapping("add")
    public ResponseEntity<JobPlanBillDeclareOperate> add(@Validated @RequestBody JobPlanBillDeclareOperate jobPlanBillDeclareOperate) {
        jobPlanBillDeclareOperate.setCreatedBy(getUsername());
        jobPlanBillDeclareOperate.setCreatedDate(new Date());
        jobPlanBillDeclareOperate.setOperateId(getUserId().intValue());
        jobPlanBillDeclareOperate.setOperateName(getUsername());
        jobPlanBillDeclareOperate.setYn(YnStatusEnum.Y.getCode().longValue());
        return ResponseEntity.ok(this.jobPlanBillDeclareOperateService.insert(jobPlanBillDeclareOperate));
    }

    /**
     * 编辑数据
     *
     * @param jobPlanBillDeclareOperate 实体
     * @return 编辑结果
     */
    @PutMapping("edit")
    public ResponseEntity<JobPlanBillDeclareOperate> edit(@Validated @RequestBody JobPlanBillDeclareOperate jobPlanBillDeclareOperate) {
        return ResponseEntity.ok(this.jobPlanBillDeclareOperateService.update(jobPlanBillDeclareOperate));
    }

    /**
     * 删除数据
     *
     * @param deleteVo 主键
     * @return 删除是否成功
     */
    @DeleteMapping("delete")
    public AjaxResult deleteById(@Validated @RequestBody DeleteVo deleteVo) {
        this.jobPlanBillDeclareOperateService.deleteById(deleteVo.getId());
        return AjaxResult.success();
    }

}

